﻿using Mockery.Core;
using Mockery.Core.CommonContainer;
using NUnit.Framework;
using Rhino.Mocks;

namespace Mockery.UnitTest
{
    [TestFixture]
    public class TypeCacheTests
    {
        /// <summary>
        /// These tests are being explicitly ommited due to a problem with
        /// System.Reflection.Emit per http://groups.google.com/group/RhinoMocks/browse_thread/thread/b2235a13f920c616?pli=1
        /// </summary>

        [Test, Explicit]
        public void TypeCache_StandardLoad()
        {
            var mocks = new MockRepository();
            var commonContainerBuilderStub = mocks.Stub<ICommonContainerBuilder>();

            var cache = new TypeCache(commonContainerBuilderStub);
            cache.AddMockedType(new TypeCacheTests());

            Assert.That(cache.GetMockedType<TypeCacheTests>(), Is.Not.Null);
        }

        [Test, Explicit]
        public void TypeCache_DuplicateLoadError()
        {
            var mocks = new MockRepository();
            var commonContainerBuilderStub = mocks.Stub<ICommonContainerBuilder>();

            var cache = new TypeCache(commonContainerBuilderStub);
            cache.AddMockedType(new TypeCacheTests());
            Assert.That(Assert.Throws<DuplicateMockException>(() => cache.AddMockedType(new TypeCacheTests())).Message,
                        Is.StringContaining("'TypeCacheTests'"));
        }

        [Test, Explicit]
        public void TypeCache_UnfoundTypeError()
        {
            var mocks = new MockRepository();
            var commonContainerBuilderStub = mocks.Stub<ICommonContainerBuilder>();

            var cache = new TypeCache(commonContainerBuilderStub);
            Assert.That(Assert.Throws<MissingMockException>(() => cache.GetMockedType<TypeCacheTests>()).Message,
                        Is.StringContaining("'TypeCacheTests'"));
        }
    }
}
